<?php
	class Maccount extends CI_Model{
		public function __construct(){
			parent::__construct();
			$this->load->database();
		}
		public function register_ok($email,$name,$passwd,$sex,$phone,$address,$city,$district,$type)
		{
			$query="INSERT INTO `account` (`name`, `email`, `password`, `sex`, `phone`, `address`, `district`, `city`,`type`, `join_day`) 
									VALUES ('$name', '$email', '".md5($passwd)."', '$sex', '$phone', '$address', '$district', '$city','$type', NOW())";
			
			$result=$this->db->query($query);
			$id_account=$this->db->insert_id() ;
			$uploadDir = '../upload/'.$id_account.'/';
			if (!file_exists($uploadDir)) mkdir($uploadDir, 0777, true);
		}
		public function login_ok($email, $passwd)
		{
			$query="SELECT * from account a WHERE a.email='$email' AND a.password='".md5($passwd)."' AND a.status=1";
			$result=$this->db->query($query);
			return $result->result_array();
		}
		
		
		public function updateperson_ok($id_account,$name,$sex,$phone,$address,$city,$district)
		{
			$query="UPDATE `account` SET `name`='$name', `sex`='$sex', `phone`='$phone', `address`='$address', `city`='$city', `district`='$district' WHERE (`id`='$id_account')";
			$result=$this->db->query($query);
		}
		
		public function confirm_password($id_account, $opassword)
		{
			$query="SELECT * from account a WHERE a.id='$id_account' AND a.password='".md5($opassword)."'";
			$result=$this->db->query($query);
			return $result->result_array();
		}
		public function changepassword_ok($id_account, $npassword)
		{
			$query="UPDATE `account` SET `password`='".md5($npassword)."' WHERE (`id`='$id_account')";
			$result=$this->db->query($query);
		}
	}
?>